<template>
    <div class="terminaManageDetail">
        <div class="container">
            <div>
                <el-row>
                    <el-button @click="returnMachine" id="button-return" type="primary" plain>返回</el-button>
                    <!-- <el-button @click="showMachine" id="button-add" type="primary" plain>添加机器</el-button> -->
                </el-row>
                <el-tabs v-model="activeName" type="border-card" @tab-click="handerTop()">
                    <el-tab-pane label="台卡" name="first">
                        <table border="0" cellspacing="0" v-if="platFromList.length!==0">
                            <thead>
                                 <tr>
                                    <th><div class="table-cell">台码编号</div></th>
                                    <th><div class="table-cell">代理商</div></th>
                                    <th><div class="table-cell">台码状态</div></th>
                                    <th><div class="table-cell">创建时间</div></th>
                                    <th><div class="table-cell">创建者</div></th>
                                    <th><div class="table-cell">操作</div></th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr v-for="(cell,index) in platFromList" :key="index" >
                                    <td>
                                        <div class="table-cell" v-html="cell.platformCode"></div>
                                    </td>
                                    <td>
                                        <div class="table-cell" v-html="cell.agent"></div>
                                    </td>
                                    <td>
                                        <div class="table-cell" v-html="cell.state"></div>
                                    </td>
                                    <td>
                                        <div class="table-cell" v-html="cell.createTime"></div>
                                    </td>
                                    <td>
                                        <div class="table-cell" v-html="cell.createBy"></div>
                                    </td>
                                    <td>
                                        <div class="table-cell" >
                                            <el-button type="text" @click="handleLook(cell)">查看二维码</el-button>
                                        </div>
                                    </td>

                                </tr>
                            </tbody>
                        </table>
                        <div style="padding:30px;text-align:center;" v-else>
                            暂无数据……
                        </div>
                        <div class="pages-control">
                            <el-pagination
                                @current-change="handleCurrentChange"
                                :current-page.sync="pages.currentPage"
                                :page-size="pages.page_size"
                                layout="prev, pager, next"
                                :total="pages.total">
                            </el-pagination>
                        </div>
                    </el-tab-pane>
                    <el-tab-pane label="智能pos机" name="second">
                       
                        智能pos机
                    </el-tab-pane>
                </el-tabs>
            </div>
        </div>

    <!-- 二维码查看 -->
    <el-dialog
        title="提示"
        :visible.sync="centerDialogVisible"
        width="30%"
        center>
        <div class="img-qr">
            <img :src="currentImg" alt="加载二维码失败！">
        </div>
        <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="centerDialogVisible = false">确 定</el-button>
        </span>
      </el-dialog>
    </div>    
</template>
<script>
export default {
    name:'terminaManageDetail',
    data() {
        return {
            activeName:'first',
            labelPosition: 'right',
           platFromList:[],
           centerDialogVisible:false,
           currentImg:"",
            options: [ {
                value: '0',
                label: '智能pos机'
            },{
                value: '1',
                label: '台卡'
            }],

            //台卡
            decometer:{
                storeName: '',//所属门店
                shopLogo:null,//门店logo
                evmImg:null,//二维码图片
                payUrl:'',//支付链接
                terminalName: '',//终端简称
                evmNo: ''//二维码编号
            },
            //智能pos
            noopsyche:{
                storeName: '',//所属门店
                machineType: '',//机器品牌
                machineNo: '',//机器号
                simNo: '',//SIM卡号
                shopLogo:null,//门店logo
                terminalName: '',//终端简称
                evmNo: ''//二维码编号
            },
            pages:{
                total:100,
                page_size:20,
                currentPage:1,
            },
        }
    },
    components: {},
    created() {
        this.init();
    },
    mounted() {},
    methods: {
      init(){
          this.handerTop();
      },
      handerTop(){
          if(this.activeName=='first'){
            this.queryPlatfrom();
          }else if(this.activeName=='second'){
            this.queryPos();
          }
      },
      handleLook(cell){
          this.currentImg = cell.qrcCode;
          this.centerDialogVisible = true;
      },
      queryPlatfrom(){
          // 查询台卡
          let token = sessionStorage.getItem(1);
          let url = `user/queryPlatFrom/${token}`;
          let params = `page=${this.pages.currentPage}&size=${this.pages.page_size}&shop_id=${this.$route.params.shopId}`;
         this.$Http.post(url,params).then(res=>{
             if(res.data.resp_code === "000000"){
                 this.platFromList = res.data.result.content;
                 this.pages.total = res.data.totalElements;
             }else{
                 this.$notify.info({
                    title: '温馨提示',
                    message: res.data.resp_message,
                    type: 'warning'
                });
             }
         }).catch(err=>{
                this.$notify.error({
                    title: '警告',
                    message: '服务器繁忙！请重新尝试！',
                    type: 'warning'
                });
         })


      },
      queryPos(){
           // 查询pos

      },
      /* 分页 */
      handleCurrentChange(value){
        // this.handerTop();
      },
    
   
   
      /* 返回上一页 */
      returnMachine(){
          this.$router.push({name: "terminalInfo"})
      },
     
      /* 查询所属门店 */
      queryStores(){
          this.loading = true;
          this.shopId = this.$route.params.shopId;
          let url = `user/store/findByShopId?shopId=${this.shopId}`;
          this.$Http.get(url,``).then(res=>{
              this.loading = false;
              if(res.data.resp_code === '000000'){
                this.terminalDetailList = res.data.result.content;
              }else{
                  this.$message(res.data.resp_message)
              }
          }).catch(err=>{
            this.loading = false;
            this.$notify.error({
                title: '错误',
                message: '获取信息失败！'
            });
        }) 
      },
      checkInfo(){
          let status = false;
          this.$refs.shopinfoForm.validate(valid=>{
              status = valid;
              if(!valid){
                 this.$notify({
                    title: '警告',
                    message: '填写的信息有误！无法提交！请重新填写！',
                    type: 'warning'
                });
                return false;
              }
          });
          return status;
      },
      /* 添加台卡 */
      addDecometer(){
          if(!this.checkInfo()){
            return;
          }
          this.decometer.terminalType=this.apply;
          this.decometer.shopId=this.shopId;
          let submitdecomenter = {...this.decometer};
          let token = sessionStorage.getItem(1);
          let url = `user/terminal/add/${token}`;
          let params = ``;
          for(let key in submitdecomenter){
             if(submitdecomenter[key]!==''&&submitdecomenter[key]!==null){
                if(params===''){
                    params = key + '=' + submitdecomenter[key];
                }else{
                    params = params +'&'+ key + '=' + submitdecomenter[key]
                } 
             }      
          }
          this.$Http.post(url,params).then(res=>{
             if(res.data.resp_code === "000000"){
                 // 添加成功
                 this.$message({
                    showClose: true,
                    message: res.data.result,
                    type: 'success'
                 });
             }
          }).catch(err=>{
              this.$notify({
                title: '添加失败！',
                message: "添加失败！请重新尝试！",
                type:"error"
            });
          })
      },
      /* 添加智能pos机 */
      addNoopsyche(){
          if(!this.checkInfo()){
            return;
          }
          this.noopsyche.terminalType=this.apply;
          this.noopsyche.shopId=this.shopId;
          let submitnoopsyche = {...this.noopsyche};
          let token = sessionStorage.getItem(1);
          let url = `user/terminal/add/${token}`;
          let params = ``;
          for(let key in submitnoopsyche){
             if(submitnoopsyche[key]!==''&&submitnoopsyche[key]!==null){
                if(params===''){
                    params = key + '=' + submitnoopsyche[key];
                }else{
                    params = params +'&'+ key + '=' + submitnoopsyche[key]
                }
             }
          }
          this.$Http.post(url,params).then(res=>{
             if(res.data.resp_code === "000000"){
                 // 添加成功
                 this.$message({
                    showClose: true,
                    message: res.data.result,
                    type: 'success'
                 });
             }
          }).catch(err=>{
              this.$notify({
                title: '添加失败！',
                message: "添加失败！请重新尝试！",
                type:"error"
            });
          })
      },
     
    }
}
</script>
<style scoped>
.terminaManageDetail{
    box-sizing: border-box;
    padding: 20px;
}
.model{
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    overflow-y: auto;
    background-color:rgba(71, 68, 68, 0.438)
}
.terminalManage-model{
    width: 500px;
    border-radius: 5px;
    background-color: rgb(253, 254, 255);
    position: absolute;
    z-index: 200;
    left: 30%;
    top: 5%;
}
.terminalManage-pos-model{
    width: 500px;
    border-radius: 5px;
    background-color: rgb(253, 254, 255);
    position: absolute;
    z-index: 200;
    left: 30%;
    top: 5%;
}
.terminalManage-m-top{
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    height: 40px;
    line-height: 40px;
    background-color: #F2F6FC;
    border-bottom: 1px solid rgb(221, 228, 233);
}
.terminalManage-m-top>span{
    padding-left: 25px;
}
.terminalManage-i-close{
    position: absolute;
    top: 10px;
    right: 10px;
}
.terminalManage-i-close:hover{
    color: red;
}
.terminalManage-m-center{
    width: 370px;
    padding-top: 10px;
    padding-left: 20px;
    padding-bottom:40px; 
    line-height: 50px;
    border-bottom: 1px solid rgb(221, 228, 233);
}
.terminal-m-bottom{
    height: 80px;
    background-color: #F2F6FC;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
    text-align: right;
    line-height: 80px;
}
.terminal-m-button{
    padding-right: 20px;
}
.filter-cell{
    display: flex;
    justify-content: space-around;
    align-items: center;
    flex-wrap: nowrap;
}
.upload-img{
    padding-left: 40px;
}
table{
    background-color: #FFF;
    width: 100%;
    font-size: 12px;
    min-width: 900px;
}
th{
    position: relative;
    word-wrap: normal;
    text-overflow: ellipsis;
    vertical-align: middle;
    border-bottom: 1px solid #ebeef5;
    
}
thead{
    padding: 8px 0;
    color: #909399;
}
tr{
    padding: 8px 0;
}
tr:hover{
    background-color: #F5F7FA;
}
td{
    border: none;
    border-bottom: 1px solid #ebeef5;
}
.table-cell{
    white-space: normal;
    word-break: break-all;
    line-height: 22px;
    padding: 10px 10px;
    text-align: center;
    min-width: 40px;
    box-sizing: border-box;
}

.pages-control{
    display: flex;
    justify-content: center;
    align-items: center;
    height: 40px;
}
#button-return{
    position: absolute;
    top: 4px;
    right: 4px;
    z-index: 10;
}
#button-add{
    position: absolute;
    top: 4px;
    right: 70px;
    z-index: 10;
}
</style>
